package com.xyzisme76.application;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

public class Menu {
    private static final int WIDTH =500;
    private static final int HEIGHT = 500;

   int menuInit(){
       JFrame jf = new JFrame("菜单" );
       //设置大小
       jf.setSize(new Dimension(WIDTH,HEIGHT));
       jf.setResizable(false);
       // 设置居中
       jf.setLocationRelativeTo(null);
       JPanel jp = new JPanel();

       ImageIcon icon = new ImageIcon("src/main/java/com/xyzisme76/application/images/sql.png");
       //创建按钮 编辑 sql语句
       JButton jbSql = new JButton(icon);
       ImageIcon icon2 = new ImageIcon("src/main/java/com/xyzisme76/application/images/mysql-view.png");
       //创建按钮 查询 sql
       JButton jbSelect = new JButton(icon2);
       ImageIcon icon3 = new ImageIcon("src/main/java/com/xyzisme76/application/images/透视表.png");
       //创建按钮 统计
       JButton jbAllInit = new JButton(icon3);
       ImageIcon icon4 = new ImageIcon("src/main/java/com/xyzisme76/application/images/脚本.png");
       //创建按钮 用户高级权限，系统维护
       JButton jbAdmin = new JButton(icon4);

       jf.add(jp);
       jp.add(jbSql);
       jp.add(jbSelect);
       jp.add(jbAllInit);
       jp.add(jbAdmin);
       jp.setLayout(new GridLayout(2,3,10,5));
       //设置可以被关闭
       jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       //可见
       jf.setVisible(true);
       jbSql.addActionListener(e -> {
            if(userRoot >= 2 )  JOptionPane.showMessageDialog(null,"您没有足够的权限！");
            else{
                new InfoIndex();
            }
       });
       jbSelect.addActionListener(e -> {
            new SqlSelect();
       });
       jbAllInit.addActionListener(e -> {
            new Statistical();
       });
       jbAdmin.addActionListener(e -> {
           if(userRoot >= 2 )  JOptionPane.showMessageDialog(null,"您没有足够的权限！");
           else{
                new RootIndex();
           }
       });
       return 1;
   }

        public Menu(int userRoot) {
        this.userRoot = userRoot;
        menuInit();
   }

   public int getUserRoot() {
        return userRoot;
    }

    public void setUserRoot(int userRoot) {
        this.userRoot = userRoot;

    }


    private int userRoot;
}
